<?php
/**
 * Answer Service
 * User: zng
 * Date: 2019/11/4
 * Time: 14:34
 */
namespace app\admin\service\order;

use app\admin\model\order\Order as OrderModels;

Class Order {

    /**
     * 首页列表
     * @param array $get 筛选条件
     * @return \think\Paginator
     */
    public function indexPaginate( array $get=[] )
    {
        $map = [];
        if ( get($get, 'order_number') ) {
            $map[] = ['order_number', '=', $get['order_number']];
        }
        $config = config('field.order');
        if ( (get($get, 'payment_status') === 0 || get($get, 'payment_status') === '0' || get($get, 'payment_status') > 0) && in_array(get($get, 'payment_status'), array_keys($config['payment_status']) ) ) {
            $map[] = [ 'payment_status', '=', $get['payment_status'] ];
        }
        $pageSize = get($get,'pageSize')>0?$get['pageSize']:20;

        return OrderModels::where($map)
            ->order('id', 'desc')
            ->paginate($pageSize);
    }

    /**
     * 批量删除
     * @param mixed $data
     * @return boolean
     */
    public function destory( $data )
    {
        return OrderModels::destroy(function($query)use($data){
            $where = ['id', '=', $data];
            if ( is_array($data) ) {
                $where = ['id', 'in', $data];
            }
            $query->where([
                $where
            ]);
        });
    }

}